//https://leetcode.cn/problems/max-consecutive-ones-iii/description/
class Solution {
public:
    int longestOnes(vector<int>& nums, int k) {
        int left = 0, right = 0;
        int n = nums.size();
        int ret = 0, len = 0;
        while (right < n)
        {
            if (nums[right] == 0)
            {
                ret++;
            }

            while (ret > k)
            {
                if (nums[left++] == 0)
                {
                    ret--;
                }
            }

            len = max(len, right - left + 1);

            right++;
        }
        return len;
    }
};